#include<iostream>
using namespace std;
const int N = 3e4 + 10;
int v[N], p[N];
int f[N];
int n, m;
int main()
{
	cin >> m >> n;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> v[i] >> x;
		p[i] = v[i] * x;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = m; j >= v[i]; j--) {
			f[j] = max(f[j], f[j - v[i]] + p[i]);
		}
	}
	cout << f[m] << endl;
	return 0;
}